package cn.getech.data.development.controller;


import cn.getech.data.development.model.vo.*;
import cn.getech.data.development.service.BdpServiceAlarmService;
import cn.getech.data.intelligence.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务告警管理
 */
@Slf4j
@Api(tags = "服务告警管理")
@RestController
@RequestMapping("/bdp/service/alarm")
public class ServiceAlarmController {

    @Resource
    BdpServiceAlarmService serviceAlarmService;

    @ApiOperation("获取服务告警分页列表")
    @ApiResponses({@ApiResponse(code = 200, message = "Success", response = AlarmVO.class)})
    @PostMapping("/page")            //bdp/service/alarm/page
    public R page(@RequestBody ServiceAlarmSearchVO vo) {
        return R.okWithPage(serviceAlarmService.serviceAlarmPage(vo));
    }

    @ApiOperation("创建和修改服务告警信息")
    @ApiResponses({@ApiResponse(code = 200, message = "Success")})
    @PostMapping("/save")            //bdp/service/alarm/save
    public R save(@RequestBody BdpServiceAlarmVO vo) {
        serviceAlarmService.saveServiceAlarm(vo);
        return R.ok();
    }

    @ApiOperation("更新服务告警状态")
    @ApiResponses({@ApiResponse(code = 200, message = "Success")})
    @GetMapping("/update/state")            //bdp/service/alarm/state
    public R updateState(@RequestParam("id") Integer id,@RequestParam("state") Integer state) {
        serviceAlarmService.updateState(id,state);
        return R.ok();
    }

    @ApiOperation("删除服务告警信息")
    @ApiResponses({@ApiResponse(code = 200, message = "Success")})
    @GetMapping("/delete")            //bdp/service/alarm/delete
    public R delete(@RequestParam("id") Integer id) {
        serviceAlarmService.delete(id);
        return R.ok();
    }

    @ApiOperation("服务告警创建人列表")
    @ApiResponses({@ApiResponse(code = 200, message = "Success")})
    @GetMapping("/user/list")            //bdp/service/alarm/user/list
    public R userList() {
        return R.okWithData(serviceAlarmService.userList());
    }

    @ApiOperation("服务告警接收人列表")
    @ApiResponses({@ApiResponse(code = 200, message = "Success")})
    @GetMapping("/receiver/list")          //bdp/service/alarm/receiver/list
    public R receiverList() {
        return R.okWithData(serviceAlarmService.receiverList());
    }

    @ApiOperation("服务组列表")
    @ApiResponses({@ApiResponse(code = 200, message = "Success", response = AlarmVO.class)})
    @GetMapping("/group/list")          //bdp/service/alarm/group/list
    public R groupList() {
        return R.okWithData(serviceAlarmService.groupList());
    }

    @ApiOperation("服务列表")
    @ApiResponses({@ApiResponse(code = 200, message = "Success", response = AlarmVO.class)})
    @GetMapping("/service/list")          //bdp/service/alarm/service/list
    public R serviceList(@RequestParam("id") Integer id) {
        return R.okWithData(serviceAlarmService.serviceList(id));
    }

}
